/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-12
 * Time: 10:02
 */
public class MyQueue {

    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode first = null;
    public ListNode last = null;

    public int usedSize = 0;

    public void offer(int val) {
        ListNode node = new ListNode(val);

        if (first == null) {
            first = last = node;
            return;
        }
        node.prev = last;
        last.next = node;
        last = node;
    }

    public int poll() {
        if (first == null) {
            return Integer.MAX_VALUE;
        }
        int val = first.val;
        if (first.next == null) {
            first = last = null;
            return val;
        }
        first = first.next;
        first.prev = null;
        return val;
    }

    public int peek() {
        if (first == null) {
            return Integer.MAX_VALUE;
        }
        return first.val;
    }

    public boolean isEmpty() {
        return first == null;
    }

}